public class L98 {

    class Solution {

        long tmp = Long.MIN_VALUE;

        public boolean isValidBST(TreeNode root) {
            if (root == null) {
                return true;
            }
            boolean leftValid = isValidBST(root.left);
            if (!leftValid) {
                return false;
            }

            boolean flag = tmp < root.val;
            tmp = root.val;

            boolean rightValid = isValidBST(root.right);
            if (!rightValid) {
                return false;
            }

            return flag;
        }
    }
}
